import request from '@/utils/request';
import { sourceUrl } from '@/config';

/**
 * 获取资讯
 */
export async function selectFiveArticle(data) {
  return request({
    url: '/news/news/fineNewsWebArticle/selectFiveArticle',
    method: 'POST',
    unNeedToken: true,
    data: data,
  });
}

/**
 * 获取售货机信息
 */
export async function selectDevicePage(data) {
  return request({
    url: '/vem/app/deviceequipment/selectDevicePage',
    method: 'POST',
    data: data,
  });
}

/**
 * 获取卡列表信息
 */
export async function getCardListByUserIdService(data) {
  return request({
    url: '/wallet/app/fineCard/getCardListByUserId',
    method: 'POST',
    data: data,
  });
}

/**
 * 获取卡二维码信息
 */
export async function getCardByIdService(data) {
  return request({
    url: '/wallet/app/fineCard/getCardById',
    method: 'POST',
    data: data,
  });
}

//我的积分
export async function getMyPointServer(data) {
  return request({
    url: '/wallet/api/pointRecord/myPoint',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

// 活动配送时间段
export async function deliveryTimeServer(data) {
  return request({
    url: '/product/product/fineActivityDeliveryTime/select',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

// 团餐商户地址查询
export async function getMerchantActivityAddressServer(data) {
  return request({
    url: '/product/activity/address/select',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

// 查询用户卡券分基本信息
export async function getUserDetailServer() {
  return request({
    url: '/product/myBalance/getDetail',
    method: 'GET',
  });
}

// 获取行政区域
export async function getAreaListServices() {
  return request({
    url: '/mb/districtList',
    method: 'GET',
  });
}

// 获取广告位信息
export async function getAdvertServices(data) {
  return request({
    url: '/news/news/advertisingPosition/selectAdvertisingListByAlias/' + data.alias,
    method: 'GET',
  });
}

// 获取首页功能导航区
export async function getNavListServices() {
  return request({
    url: '/product/product/getProductHome',
    method: 'GET',
  });
}

// 获取一级行业下有店铺的二级行业
export async function getSecondIndustryServices(data) {
  const { firstIndustryId } = data;
  return request({
    url: '/product/product/getSecondIndustry/' + firstIndustryId,
    method: 'GET',
  });
}

// 获取商户信息
export async function getLocalOrgDetailServices(data) {
  return request({
    url: '/product/applet/localOrgDetail',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

// 获取自提点列表
export async function getSelfTakeService(data) {
  return request({
    url: '/merchant/listOrgSelfExtraction',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
    data: data,
    method: 'POST',
  });
}

/**
 * 根据IP获取的用户位置信息
 */
export async function getLocationByIPServices() {
  return request({
    url: '/mb/ips',
    method: 'GET',
  });
}

/**
 * 获取店铺基本信息
 */
export async function getOrgInfoWithLocationServices(data) {
  const { merchantId, orgId, longitude, latitude } = data;
  return request({
    url: `/product/order/confirmInfo/listSelfRaisingOrg?merchantId=${merchantId}&orgId=${orgId}&longitude=${longitude}&latitude=${latitude}`,
    method: 'GET',
  });
}

// 获取商城金刚区行业
export async function getShopIndustryAdjustServices() {
  return request({
    url: '/product/product/getTaiHuProductHome',
    method: 'GET',
  });
}

/**
 * 获取搜索结果
 */
export async function getSearchResultServer(data) {
  return request({
    url: `/search/shop`,
    method: 'GET',
    data,
  });
}

/**
 * 绑定数字钱包发送验证码
 */
export async function getWalletBindCodeService(data) {
  return request({
    url: '/wallet/app/fineUserDigitalWallet/sendAuthCodeShop',
    method: 'POST',
    data,
  });
}

/**
 * 绑定数字钱包
 */
export async function getWalletBindService(data) {
  return request({
    url: '/wallet/app/fineUserDigitalWallet/bindingDigitalWalletShop',
    method: 'POST',
    data,
  });
}

/**
 * 检查数字钱包是否绑定
 */
export async function checkWalletBindService() {
  return request({
    url: '/wallet/app/fineUserDigitalWallet/selectDigitalWalletByPhone',
    method: 'GET',
  });
}

/**
 * 数字钱包支付发送验证码
 */
export async function sendCodeByDigitWalletService(data) {
  return request({
    url: '/notification/codes/sms',
    method: 'POST',
    data,
  });
}

/**
 * 数字钱包支付校验验证码
 */
export async function checkCodeByDigitWalletService({ code }) {
  return request({
    url: `/notification/codes/sms/verify?code=${code}`,
    method: 'GET',
  });
}

/**
 * 推荐店铺列表
 */
export async function topOrgListService(data) {
  return request({
    url: '/product/featuredFirstProduct/topOrgList',
    method: 'POST',
    data,
  });
}

// 店铺商品搜索
export async function orgSearchProductListServer(data) {
  return request({
    url: `/search/org-product`,
    method: 'GET',
    data,
  });
}

// 获取物流公司列表
export async function getLogisticsCompanyServer() {
  return request({
    url: '/merchant/merchant/fine-logistics/getAllLogistics',
    method: 'GET',
  });
}

/**
 * 添加物流信息
 */
export async function addLogisticsInfoServer(data) {
  return request({
    url: '/product/product/orderAdjustmentRelation/applyReturnProduct',
    method: 'POST',
    data,
  });
}

/**
 * 修改物流信息
 */
export async function modifyLogisticsInfoServer(data) {
  return request({
    url: '/product/product/orderAdjustmentRelation/modifyLogisticsInfo',
    method: 'PUT',
    data,
  });
}

// 积分规则
export async function pointConfigServer(data) {
  return request({
    url: `/wallet/api/pointConfig`,
    method: 'GET',
    data,
  });
}

// 帮助中心类目和文章
export async function getCustomerServiceListServer(data) {
  return request({
    url: `/news/app/newsArticle/getRandomArticles/${data.alias}`,
    method: 'GET',
  });
}

// 搜索文章
export async function getCustomerServiceSearchServer(data) {
  return request({
    url: `/news/app/newsArticle/getArticles`,
    method: 'GET',
    data,
  });
}

// 文章详情
export async function getCustomerServiceArticleServer(data) {
  return request({
    url: `/news/app/newsArticle/fineNewsWebArticle/${data.id}`,
    method: 'GET',
  });
}

// 文章相关推荐
export async function getCustomerServiceAdjustServer(data) {
  return request({
    url: `/news/app/newsArticle/relatedRecommendations/${data.id}`,
    method: 'GET',
  });
}

// 文章是否解决了问题
export async function customerServiceMarkServer(data) {
  return request({
    url: `/news/app/newsArticle/markResolved`,
    method: 'PUT',
    data,
  });
}

// 获取页面配置
export async function getCustomePageConfigServices(data) {
  const { merchantId = '0', pageName = 'home' } = data;
  const time = new Date().getTime();
  return request({
    baseUrl: sourceUrl,
    url: `ht-fine-merchant/${merchantId}/${pageName}/config.json?time=${time}`,
    method: 'GET',
    noToast: true,
  });
}

// 获取预览页面配置
export async function customerServicePreviewServer(data) {
  return request({
    url: `/merchant/merchant/merchantPageComponent/appPagepreview`,
    method: 'POST',
    data,
  });
}

// 微信加密jsapi
export async function getJsApiTicketServer(data) {
  return request({
    url: `/merchant/merchant/colorConfig/getJsapiTicket`,
    method: 'GET',
    data,
  });
}

// 应用设置
export async function appConfigServer(appId) {
  return request({
    url: `/merchant/merchant/colorConfig/appDetail/${appId}`,
    method: 'GET',
  });
}

// 校验token是否有效
export async function checkTokenService(data) {
  return request({
    url: '/mb/tokens/verify/applet',
    method: 'POST',
    data,
  });
}

// 获取协议
export async function getAgreementInfoService(data) {
  return request({
    url: '/merchant/wechat/agreementConfig/getAgreementConfig?type=' + data.type,
    method: 'GET',
  });
}

// 查询协议版本号
export async function getAgreementVersionService(data) {
  return request({
    url: '/merchant/wechat/agreementConfig/getVersion?type=' + data.type,
    method: 'GET',
  });
}
